In-Circuit Debugger

2. The Hardware
2.1. Processor

PIC16F876

The ICD is containing a PIC itself running at 20MHz clock. Depending of your spare box's contents, you can either take a PIC16F876 (28 pins, picture at right) or the larger PIC 16F877 (40 pins). The PIC's digital I/O pins connects to the serial interface (RC6-7, RB4-5) and the target processor (RC0-5). Further, the analog inputs RA0, RA1 and RA3 are used to measure the voltage levels of Target's MCLR, Vdd and Vpp.


Using a PIC16F876A

People reported to me that using the newer A-revision is possible, too. But you will need some kind of different firmware, if you want to use a PIC16F876A or PIC16F877A! (A new bootloader is needed because the device differs in the way of self-programming the flash memory) See the guestbook/forum!

(I have not tested this devices by myself)

2.2. Serial Interface

max232

As RS-232 Transceiver, a common MAX232 in standard application is used. If you take a MAX232A instead, replace the 1uF capacitors by 0.1uF ones. To the 9 pin female SUB-D connector establishing the connection to the COM-port, there is also a resistor and a zener diode connected for generating a reset signal (might be omitted...).

Using USB instead of RS-232?

Instead of a MAX232, an USB-to-serial chip like PL2303 (3V but 5V-tolerant) or FT232 can be used. They need few external components, but have a very small package making soldering and wiring without a pcb very difficult... Using USB, we can power our ICD2 from USB-bus without need for a heavy external power supply. See the new USB-ICD.

max232 BTW: For many people, the zener diode seems to be some kind of an exotic device: you can replace it diode by two standard diodes, e.g. 1N4148:

2.3. Supply Voltages

7805

For seldom home use it seems good to take one power supply delivering the progamming voltage Vpp (+13V) and derive from that Vdd (+5V) via a 7805 voltage regulator. So we can adjust the Vpp if necessary, too. You could also take +5V (eg. from USB or the target board) and use a DC/DC converter for obtaining Vpp.




2.4. Target Processor Interface

The Voltage of target's MCLR is controlled by RC0, RC1 and RC2 (all active low). When RC0 goes low, Vpp is enabled, and RC1 low enables Vdd. RC2 pulls MCLR to GND on demand - this is necessary if there is a pull-up resistor at the target's MCLR pin.
The target processor gets connected by the three wires TARGET PGD, TARGET PGC and TARGET MCLR. Of Course, for ensuring equal potentials a ground connection Vss to the target board is required, too.

New Version using OpAmp
Target

Take a LM358 type OpAmp or similar. Because of some voltage drop across the OpAmp, its supply (label Vpp) has to be 15V (or higher) now!! At the output of the OpAmp, there should be a current limiting resistor (about 33-50Ohm) in case your OpAmp is capable of delivering high output currents. The potentiometer is about 47KOhm and allows to adjust the programming voltage over a wide range. You should tweak it to about 13V (see Voltage Monitor at ICD's Status Dialog in MPLAB!). Of course, for a fixed voltage two normal resistors can be used instead of the poti, too. Since the programming voltage is generated only on demand but the ICD firmware wants to be able to monitor it all the time, we have to create some kind of fake voltage for RA3 (its ADC value won't be a real existing voltage any more, but the firmware will think it's in range): change the value of R13 to 4k7 and R14 to 6k8 and connect R13 to Vdd instead of Vpp!!
This kind of target interface has first been implemented in the USB-ICD - perhaps you should take a look at the schematics there, too!

Old Version using discrete transistors
Target

The two diodes should be germanium or schottky type because of the lower voltage drop across them. The values of resistors together with the defined limited current amplification of the B-series transistors ensure that there will flow sufficient but not too high currents into the MCLR-Pin so the target's PIC won't latch-up.
If you use different types of transistors, you have to adjust R1 to R4. If you spend extra current limiting resistors (about 50Ohm) in line with Vpp/Vdd at T2/T3, R1 to R4 aren't cirital any more. You should be able to use 10K for R1 to R4 then.

Simplification

If there is no pull-up resistor at the target's MCLR pin, you can ommit T4, R4 and D2 for pulling MCLR to ground because the resistors R5 and R6 of the voltage monitoring circuit already ensure ground level. Using this cheap version you have to remove the target's pull-up resistor at MCLR if existing everytime you connect your ICD, so I think you should add these three parts.
Possible scenarios: this ICD stays connected all the time, you use it for programming only, you can remove the pull-up easily when connecting the ICD (e.g. breadboard...)